package ke01.am;

import java.util.Arrays;
import java.util.Date;

public class GeneratedUser implements Loginable {
	private String name;
	private byte[] password;

	private Date birthDate;
	private String lastIp;

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param name
	 * @param password
	 * @param birthDate
	 * @param lastIp
	 */
	public GeneratedUser(String name, byte[] password, Date birthDate,
			String lastIp) {
		super();
		this.name = name;
		this.password = password;
		this.birthDate = birthDate;
		this.lastIp = lastIp;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ke01.am.Loginable#login(java.lang.String, byte[], java.lang.String)
	 */
	@Override
	public boolean login(String userName, byte[] passwd, String currentIp) {
		if (userName.equals(this.name) && passwd.equals(this.password)) {
			this.lastIp = currentIp;
			return true;
		}
		return false;
	}

	public String getName() {
		return name;
	}

	public byte[] getPassword() {
		return password;
	}

	public void setPassword(byte[] password) {
		this.password = password;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getLastIp() {
		return lastIp;
	}

	public void setLastIp(String lastIp) {
		this.lastIp = lastIp;
	}

	@Override
	public String toString() {
		return "GeneratedUser [name=" + name + ", password="
				+ Arrays.toString(password) + ", birthDate=" + birthDate
				+ ", lastIp=" + lastIp + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + Arrays.hashCode(password);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GeneratedUser other = (GeneratedUser) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (!Arrays.equals(password, other.password))
			return false;
		return true;
	}
}
